package com.lzg.prototype.utils;


import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author lizhigang Date: 2019/4/22 14:34
 * @description: 根据对象获取对应的clone对象并赋值
 */
public class BeanUtil {

	public static void copyProperties(Object source, Object target) throws InvocationTargetException, IllegalAccessException, InstantiationException {
		if(null == source || null == target){
			System.out.println("非法参数");
			return;
		}
		Class<?> actualTarget = target.getClass();
		Class<?> sourceClass = source.getClass();
		Method[] methodsTarget =  actualTarget.getMethods();
		Map setMap = new HashMap();
		Map getMap = new HashMap();
		for (Method m : methodsTarget){
			if(m.getName().startsWith("set")){
				setMap.put(m.getName(),m);
				System.out.println(setMap.get(m.getName()));
			}

		}
		for (Object m2 : setMap.keySet()){
			Method m3 = (Method)setMap.get(m2);
			m3.invoke(m3.getDeclaringClass().newInstance(),"21213");
			System.out.println(m3);
			//执行target set方法
		}
	}

	public static String upperFirstCase(String str){
		if(str==null||"".equals(str)){return null;}
		char[] chars = str.toCharArray();
		chars[0]-=32;
		return String.valueOf(chars);
	}
}
